package com.ruoyi.project.product.sku.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.product.sku.domain.ProductSku;
import com.ruoyi.project.product.sku.service.IProductSkuService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品skuController
 * 
 * @author wyh
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/product/sku/api")
public class ProductSkuApiController extends BaseController
{
    @Autowired
    private IProductSkuService productSkuService;

    /**
     * SKU查询商品
     */
    @GetMapping("/querySku")
    public AjaxResult querySku(ProductSku scProductSku)
    {
        //校验参数
        Long productId = scProductSku.getProductId();
        if(productId == null){
            return AjaxResult.error("参数检验失败");
        }

        String skuAttribute = scProductSku.getSkuAttribute();
        if(StringUtils.isBlank(skuAttribute)){
            return AjaxResult.error("参数检验失败");
        }

        ProductSku scProductSku1 = new ProductSku();
        scProductSku1.setProductId(productId);
        scProductSku1.setSkuAttribute(skuAttribute);
        scProductSku1.setIsReveal("是");

        List<ProductSku> list = productSkuService.userSelectProductSkuList(scProductSku1);
        if(ObjectUtils.isEmpty(list)){
            return AjaxResult.error("sku不存在");
        }


        return AjaxResult.success(list.get(0));
    }

}
